package com.jy.qnbbs.controller;

import com.jy.qnbbs.entity.BbsDetail;
import com.jy.qnbbs.entity.BbsSort;
import com.jy.qnbbs.service.BbsDetailService;
import com.jy.qnbbs.service.BbsSortService;
import com.jy.qnbbs.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class QnbbsController {


    @Autowired
    public BbsSortService bbsSortService;

    @Autowired
    public BbsDetailService bbsDetailService;

    @Value("${spring.profiles}")
    private String profilesName;

    @GetMapping("/getProfilesNameConfig")
    public String getProfilesNameCongig(){
        return profilesName;
    }


    /** 获取讨论版区 */
    @GetMapping("/getBbsSortList")
    public Result<List<BbsSort>> getBbsSortList(){
        return bbsSortService.queryAllBbsSort();
    }


    /** 查询帖子信息 */
    @GetMapping("/getBbsDetailListBySortId")
    public Result<List<BbsDetail>> getBbsDetailListBySortId(int sortId){
        return bbsDetailService.queryBbsDetailBySortId(sortId);
    }

    /** 发帖 */
    @PostMapping("/posting")
    public Result<BbsDetail> posting(BbsDetail bbsDetail){
        return bbsDetailService.addBbsDetail(bbsDetail);
    }

    /** 检查帖子名 */
    @PostMapping("/checkTitleName")
    public Result checkTitleName(String titleName){
        return bbsDetailService.checkTitle(titleName);
    }





}
